#include "libca.h"
//*
//**************************************************************************************************
//???       : ??????(TCU)?????
//???       : libtcu.h
//               ??:??????????????????,????????????,????????????
//????     : libtcu.so (????:/usr/lib/)
//?????? : ????????????????????,???????????,??????
//               ????????????????????
//??         : 1.04
//--------------------------------------------------------------------------------------------------
//??         : ??????????????????????????,?????????,??
//               ?????????????????
//
//--------------------------------------------------------------------------------------------------
//????     : 
//? ?        ??            ???? 
//2015/12/09   1.00             ??
//2015/12/09   1.01             ??ESAM?PSAM????,?????????
//2015/12/09   1.02             ??InitESAM/InitPSAM??????fd??????????
//2015/12/10   1.03             ????/GPS???????
//2015/12/10   1.04             ??ESAM???BDGPS???
//
//**************************************************************************************************
//
//* ????(c) 2015, ??????, ??????
//
//**************************************************************************************************
//

#ifndef LIB_TCU_H
#define LIB_TCU_H


//?????
#define ERROR_NOSUPPORT	-5		//????????
#define ERROR_SYS		-4		//??API????(????????)
#define ERROR_INPARA	-3		//????(?????????????)
#define ERROR_TIMEOUT	-2		//????
#define ERROR_FAIL		-1		//????,????
#define ERROR_OK		 0		//????

//?????
#define	TCU_IOCTL_BASE	'E'


//************************************************************
//*-----------------------------------------------------------
//*
//**   ESAM??????
//*
//*-----------------------------------------------------------
//************************************************************

#ifdef __cplusplus
extern "C" {
#endif


	//*------------------------------------------------------------------------------------------------
	//* ????:  InitEsam
	//* ????:  ESAM???
	//* ????:  ?
	//* ???  :  
	//*                ??,??:ERROR_OK(==0);
	//*                ??,??(ERROR_FAIL)
	//* ??    :  ?
	//*------------------------------------------------------------------------------------------------
	extern int InitEsam();


	//*------------------------------------------------------------------------------------------------
	//* ????:  ResetEsam
	//* ????:  ESAM????
	//* ????:
	//*           -- Rstcmd:  - 0  ???, 1  ???
	//* ???  :  ????ERROR_OK(==0);????(ERROR_FAIL)
	//* ??    :  ?
	//*------------------------------------------------------------------------------------------------
	extern int ResetEsam(int Rstcmd);


	//*------------------------------------------------------------------------------------------------
	//* ????:  ReadEsam
	//* ????:  ?ESAM??
	//* ????:
	//*           -- buffer:     - ??????????
	//*           -- uWntLen:    - ??????????
	//*           -- pGetlen:    - ???????????
	//*           -- timesoutus: - ???????????,??: useconds(??)
	//*                            ?timesoutus=0,??????.
	//* ???  :  ????ERROR_OK(==0);????(ERROR_INPARA/ERROR_TIMEOUT/ERROR_SYS/ERROR_NOSUPPORT/ERROR_FAIL)
	//* ??    :  
	//*------------------------------------------------------------------------------------------------
	extern int ReadEsam(unsigned char *buffer, unsigned int uWntLen, unsigned int *pGetlen, unsigned int timesoutus);


	//*------------------------------------------------------------------------------------------------
	//* ????:  WriteEsam
	//* ????:  ?ESAM???
	//* ????:
	//*           -- buffer:     - ??????????
	//*           -- len:        - ???????(??)
	//* ???  :  ????ERROR_OK(==0);????(ERROR_INPARA/ERROR_TIMEOUT/ERROR_SYS/ERROR_NOSUPPORT/ERROR_FAIL)
	//* ??    :  
	//*            
	//*------------------------------------------------------------------------------------------------
	extern int WriteEsam(unsigned char *buffer, unsigned int len);


	//*------------------------------------------------------------------------------------------------
	//* ????:  EsamStop
	//* ????:  ??
	//* ????:
	//* ???  :  ????ERROR_OK(==0);????(ERROR_FAIL)
	//* ??    :  ?
	//*------------------------------------------------------------------------------------------------
	extern int StopEsam();

#ifdef __cplusplus
}
#endif


//************************************************************
//*-----------------------------------------------------------
//*
//**   PSAM??????
//*
//*-----------------------------------------------------------
//************************************************************
#if 0
#ifdef __cplusplus
extern "C" {
#endif


	//*------------------------------------------------------------------------------------------------
	//* ????:  InitPsam
	//* ????:  PSAM???
	//* ????:  ?
	//*
	//* ???  :  
	//*                ??,??:ERROR_OK(==0);
	//*                ??,??(ERROR_FAIL)
	//* ??    :  ?
	//*------------------------------------------------------------------------------------------------
	extern int InitPsam();

	//*------------------------------------------------------------------------------------------------
	//* ????:  ResetPsam
	//* ????:  PSAM????
	//* ????:
	//*           -- Rstcmd:    - 0  ???, 1  ???
	//* ???  :  ????ERROR_OK(==0);????(ERROR_FAIL)
	//* ??    :  ?
	//*------------------------------------------------------------------------------------------------
	extern int ResetPsam(int Rstcmd);


	//*------------------------------------------------------------------------------------------------
	//* ????:  ReadPsam
	//* ????:  ?PSAM??
	//* ????:
	//*           -- buffer:     - ??????????
	//*           -- uWntLen:    - ??????????
	//*           -- pGetlen:    - ???????????
	//*           -- timesoutus: - ???????????,??: useconds(??)
	//*                            ?timesoutus=0,??????.
	//* ???  :  ????ERROR_OK(==0);????(ERROR_INPARA/ERROR_TIMEOUT/ERROR_SYS/ERROR_NOSUPPORT/ERROR_FAIL)
	//* ??    :  
	//*------------------------------------------------------------------------------------------------
	extern int ReadPsam(unsigned char *buffer, unsigned int uWntLen, unsigned int *pGetlen, unsigned int timesoutus);



	//*------------------------------------------------------------------------------------------------
	//* ????:  WritePsam
	//* ????:  ?PSAM???
	//* ????:
	//*           -- buffer:     - ??????????
	//*           -- len:        - ???????
	//* ???  :  ????ERROR_OK(==0);????(ERROR_INPARA/ERROR_TIMEOUT/ERROR_SYS/ERROR_NOSUPPORT/ERROR_FAIL)
	//* ??    :  
	//*            
	//*------------------------------------------------------------------------------------------------
	extern int WritePsam(unsigned char *buffer, unsigned int len);


	//*------------------------------------------------------------------------------------------------
	//* ????:  StopPsam
	//* ????:  ??
	//* ????:
	//*            --psam_fd:    -?PSAM?????
	//* ???  :  ????ERROR_OK(==0);????(ERROR_FAIL)
	//* ??    :  ?
	//*------------------------------------------------------------------------------------------------
	extern int StopPsam();

#ifdef __cplusplus
}
#endif
#endif


//************************************************************
//*-----------------------------------------------------------
//*
//**   IO??????
//*
//*-----------------------------------------------------------
//************************************************************

#ifdef __cplusplus
extern "C" {
#endif

#define DO_0 0
#define DO_1 1
#define DO_2 2
#define DO_3 3
#define DO_4 4
#define DO_5 5
//#define DO_0 48
//#define DO_1 49
//#define DO_2 50
//#define DO_3 51
//#define DO_4 52
//#define DO_5 53

#define DI_0 0
#define DI_1 1
#define DI_2 2
#define DI_3 3
#define DI_4 4
#define DI_5 5
//#define DI_0 58//GPMC_A10 GPIO1_26//????
//#define DI_0 22/* GPMC_AD8:GPIO0_22 */
//#define DI_1 23/* GPMC_AD9:GPIO0_23 */
//#define DI_2 26/* GPMC_AD10:GPIO0_26 */
//#define DI_3 27/* GPMC_AD11:GPIO0_27 */
//#define DI_4 46/* GPMC_AD14:GPIO1_14 */
//#define DI_5 47/* GPMC_AD15:GPIO1_15 */



	//*--------------------------------------------------------------------------
	//* ????:  InitExIOState
	//* ????:  ???GPIO??
	//* ????:  ?
	//*
	//* ???  :  ????ERROR_OK(==0);????(ERROR_FAIL)
	//* ??    :   ?
	//*--------------------------------------------------------------------------
	extern int InitExIOState();


	//*--------------------------------------------------------------------------
	//* ????:  SetExIOOutState
	//* ????:  ??GPIO?????,???IO?????
	//* ????:
	//*           -- gpio:    - IO???
	//*           -- state:   - IO????(0:??/1:??)
	//*
	//* ???  :  ????ERROR_OK(==0);????(ERROR_FAIL)
	//* ??    :   ?
	//*--------------------------------------------------------------------------
	extern int SetExIOOutState(int gpio, int state);

	//*--------------------------------------------------------------------------
	//* ????:  GetExIOOutState
	//* ????:  ?????????IO???????
	//* ????:
	//*           -- gpio:     - IO???
	//*           -- curstate: - ??IO???????(0:??/1:??)
	//*
	//* ???  :  ????ERROR_OK(==0);????(ERROR_FAIL)
	//* ??    :   ?
	//*--------------------------------------------------------------------------
	extern int GetExIOOutState(int gpio,int *curstate);


	//*------------------------------------------------------------------------------------------------
	//* ????:  GetExIOInValue
	//* ????:  ?????????IO??????
	//* ????:
	//*           -- gpio:     - IO???
	//*           -- curval:   - ??IO???????(0:???/1:???)
	//*
	//* ???  :  ????ERROR_OK(==0);????(ERROR_INPARA/ERROR_TIMEOUT/ERROR_SYS/ERROR_NOSUPPORT/ERROR_FAIL)
	//* ??    :   ?
	//*------------------------------------------------------------------------------------------------
	extern int GetExIOInValue(int gpio,int *curval);

#ifdef __cplusplus
}
#endif


//************************************************************
//*-----------------------------------------------------------
//*
//**   ????????
//*
//*-----------------------------------------------------------
//************************************************************

#ifdef __cplusplus
extern "C" {
#endif

	//*--------------------------------------------------------------------------
	//* ????:  GetMobileSignal
	//* ????:  ????????
	//* ????:
	//*           ?
	//*
	//* ???  :  ??????
	//* ??    :   
	//*--------------------------------------------------------------------------
	extern int GetMobileSignal();


	//*--------------------------------------------------------------------------
	//* ????:  ChangeSimChan
	//* ????:  ??SIM????
	//* ????:
	//*           -- chan:   - SIM??? (0:sim0 / 1:sim1)
	//*
	//* ???  :  ????ERROR_OK(==0);????(ERROR_FAIL)
	//* ??    :   ??sim0???
	//*--------------------------------------------------------------------------
	extern int ChangeSimChan(int chan);

	//*--------------------------------------------------------------------------
	//* ????:  GetCurSimChan
	//* ????:  ??????SIM???
	//* ????:
	//*           -- chan:   - ??SIM??? (0:sim0 / 1:sim1)
	//*
	//* ???  :  ????ERROR_OK(==0);????(ERROR_FAIL)
	//* ??    :   ?
	//*--------------------------------------------------------------------------
	extern int GetCurSimChan(int *chan);


#ifdef __cplusplus
}
#endif


//************************************************************
//*-----------------------------------------------------------
//*
//**   ??/GSP????
//*
//*-----------------------------------------------------------
//************************************************************
#ifdef __cplusplus
extern "C" {
#endif

	//*--------------------------------------------------------------------------
	//* ????:  InitBDGPS
	//* ????:  ?????/GPS??
	//* ????:
	//*           -- bdgps_fd   ??/GPS???????
	//*
	//* ???  :  ????ERROR_OK(==0);????(ERROR_FAIL)
	//* ??    :   
	//*--------------------------------------------------------------------------
	extern int InitBDGPS(int *bdgps_fd);


	//*--------------------------------------------------------------------------
	//* ????:  GetBDGPSState
	//* ????:  ??????/GPS???
	//* ????:
	//*           -- bdgps_fd       - ??/GPS???????
	//*           -- bdgps_state    - ??????GPS???:??:'V'(86)-??,'A'(65)-??,??????
	//* ???    :  ????ERROR_OK(==0);????(ERROR_FAIL)
	//* ??         :   
	//*--------------------------------------------------------------------------
	extern int GetBDGPSState(int bdgps_fd,int * bdgps_state);

	//*--------------------------------------------------------------------------
	//* ????:  GetBDGPSData
	//* ????:  ????/GPS???????????
	//* ????:
	//*           -- bdgps_fd          - ??/GPS???????
	//*           -- bdgps_loca_state  - ???????:'V'(86)-??,'A'(65)-??,??????
	//*           -- bdgps_we          - ???????:'W'(87)-??,'E'(69)-??,?????
	//*           -- bdgps_Longitude   - ?? ??0.0001,??:
	//*           -- bdgps_ns          - ???????:'N'(78)-??,'S'(83)-??,?????
	//*           -- bdgps_Latitude    - ?? ??0.0001,??:
	//*           -- bdgps_Altitude    - ?? ??0.0001,??:571000,??57.1?
	//*           -- bdgps_Time   	   - ??,??:?1970-01-01 0:00:00????UTC???
	//*
	//* ??? :  ????ERROR_OK(==0);????(ERROR_FAIL)
	//* ??   :   ?
	//*--------------------------------------------------------------------------
	extern int GetBDGPSData(int             bdgps_fd,
			char	        *bdgps_loca_state,
			char	        *bdgps_we,
			unsigned int	*bdgps_Longitude,
			char	        *bdgps_ns,
			unsigned int    *bdgps_Latitude,
			unsigned int    *bdgps_Altitude,
			unsigned int    *bdgps_Time);



#ifdef __cplusplus
}
#endif






//************************************************************
//*-----------------------------------------------------------
//*
//*                ?????????
//*
//*-----------------------------------------------------------
//************************************************************

#ifdef __cplusplus
extern "C" {
#endif

	//*------------------------------------------------------------------------------------------------
	//* ????:  EnableWtd
	//* ????:  ???????
	//* ????:
	//*           -- TimeOut:     - ????????????(?)
	//*
	//* ???:      ????ERROR_OK(==0);????(ERROR_INPARA/ERROR_TIMEOUT/ERROR_SYS/ERROR_NOSUPPORT/ERROR_FAIL)
	//* ??:     ?
	//*------------------------------------------------------------------------------------------------
	extern int EnableWtd(int TimeOut);


	//*------------------------------------------------------------------------------------------------
	//* ????:  FeedWtd
	//* ????:  ????
	//* ????:  ?
	//*
	//* ???:        ????ERROR_OK(==0);????(ERROR_INPARA/ERROR_TIMEOUT/ERROR_SYS/ERROR_NOSUPPORT/ERROR_FAIL)
	//* ??:      ?
	//*------------------------------------------------------------------------------------------------
	extern int FeedWtd(void);


	//*------------------------------------------------------------------------------------------------
	//* ????:  DisableWtd
	//* ????:  ?????
	//* ????:  ?
	//*
	//* ???:        ????ERROR_OK(==0);????(ERROR_INPARA/ERROR_TIMEOUT/ERROR_SYS/ERROR_NOSUPPORT/ERROR_FAIL)
	//* ??:      ?
	//*------------------------------------------------------------------------------------------------
	extern int DisableWtd(void);

#ifdef __cplusplus
}
#endif


#endif  //LIB_TCU_H

